import re

# 打开并读取日志文件
log_file_path = r'F:\Gstar\cryptology\Experiment\对比实验记录\resnet18RDminmax.log' # 更改为您的日志文件路径
with open(log_file_path, 'r') as file:
    log_content = file.readlines()

# 定义正则表达式
param_regex = re.compile(r'^(train_data_type|test_data_type|perturb_type|poison_rate|perturb_tensor_filepath):\s*(.+)$')
epoch_regex = re.compile(r'^.*epoch=(\d+).*global_step=(\d+).*acc=([0-9.]+).*acc_avg=([0-9.]+).*loss=([0-9.]+).*')
eval_regex = re.compile(r'^.*Eval Loss:([0-9.]+)\s+Eval acc: ([0-9.]+)')

# 存储提取的数据
params = {}
epochs_info = []
eval_info = []

# 提取数据
for line in log_content:
    param_match = param_regex.match(line)
    if param_match:
        params[param_match.group(1)] = param_match.group(2)
    
    epoch_match = epoch_regex.match(line)
    if epoch_match:
        epochs_info.append({
            'epoch': epoch_match.group(1),
            'global_step': epoch_match.group(2),
            'acc': epoch_match.group(3),
            'acc_avg': epoch_match.group(4),
            'loss': epoch_match.group(5)
        })
    
    eval_match = eval_regex.match(line)
    if eval_match:
        eval_info.append({
            'eval_loss': eval_match.group(1),
            'eval_acc': eval_match.group(2)
        })

# 打印提取的数据
print("Parameters:")
for key, value in params.items():
    print(f"{key}: {value}")

print("\nEpoch Information:")
for epoch in epochs_info:
    print(epoch)

print("\nEval Information:")
for eval in eval_info:
    print(eval)